// Functions.h
//

#ifndef FUNCTIONS_H
#define FUNCTIONS_H

#define MaxPacketLength 100	//The maximum number of bytes that a packet can contain

typedef unsigned char byte;

typedef enum _SignalState
{
	RED = 0,
	YELLOW = 1,
	GREEN = 2,
	STOP = RED,
	SLOW = YELLOW,
	GO = GREEN
} SignalState;


typedef struct _comPacket
{
	byte PRE;
	byte DES;
	byte SRC;
	byte FLG;
	byte GRP;
	byte LEN;
	byte DAT[MaxPacketLength-6];
	byte CHK;

} comPacket;
	
comPacket initComPacket(int isGroup,int isPing,int isStartup,int isWarning,int isResponse,int groupNumber,
						int packetNumber,int length,int destination, int source,unsigned char * data);

int toByteArray(byte * byte, comPacket * packet);
void store_DataIn(byte inByte);
void doPacket(comPacket * packet);
void doApplication(byte data[]);
void sendPing(int isResponse);
void sendStartup(int isWarning, char * message, int mlen);
void sendCMDFront(byte* trainId, byte *results);
void sendCMDBack(byte* trainId, byte *results);
void sendCMDError(byte errorCode);

#endif

